﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using HtmlAgilityPack;
using System.Collections.Generic;

namespace RssReaderTemplate.Model.TagProcessors
{
    public class AProcessor : TagProcessor
    {
        public AProcessor() : base("a")
        {

        }

        private bool IsBold(IDictionary<string, object> processingContext)
        {
            object isBold;
            return processingContext.TryGetValue("IsBold", out isBold) && ((int)isBold) > 0;
        }

        private bool IsItalic(IDictionary<string, object> processingContext)
        {
            object isItalic;
            return processingContext.TryGetValue("IsItalic", out isItalic) && ((int)isItalic) > 0;
        }

        public override ContentFragment PreProcessTag(HtmlNode node, IDictionary<string, object> processingContext)
        {
            
            bool bold = IsBold(processingContext);
            bool italic = IsItalic(processingContext);
            var link = new LinkFragment(node.Attributes["href"].Value, node.InnerText, bold, italic);
            node.RemoveAllChildren();
            return link;
        }

        public override ContentFragment PostProcessTag(HtmlNode node, IDictionary<string, object> processingContext)
        {
            return null;
        }
    }
}
